using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Beta_fundies_controls_admin_Colors_EditColors : System.Web.UI.UserControl
{
    public void Refresh()
    {
        gridColors.DataSource = DAL.ArchiveBackgrounds.All();
        gridColors.DataBind();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Refresh();
        }
    }

    protected void SaveColor(object sender, CommandEventArgs e)
    {
        long id;
        if (Int64.TryParse(e.CommandArgument.ToString(), out id))
        {
            Control parent = ((Control)sender).Parent;
            TextBox txtYearMonth = parent.FindControl("txtYearMonth") as TextBox;
            TextBox txtColor = parent.FindControl("txtColor") as TextBox;

            if (txtYearMonth != null && txtColor != null)
            {
                DAL.ArchiveBackground myBG = DAL.ArchiveBackgrounds.Item(id);
                if (myBG != null)
                {
                    myBG.YearMonth = txtYearMonth.Text;
                    myBG.Color = txtColor.Text;

                    DAL.ArchiveBackgrounds.Save(myBG);
                }
            }
        }
    }
}
